<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Vue规范 | 孙加俊的个人博客</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/sjj-blog/favicon.ico">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/sjj-blog/assets/css/0.styles.a5cb6817.css" as="style"><link rel="preload" href="/sjj-blog/assets/js/app.ab5bad9b.js" as="script"><link rel="preload" href="/sjj-blog/assets/js/3.136f62ef.js" as="script"><link rel="preload" href="/sjj-blog/assets/js/1.a27fba8e.js" as="script"><link rel="preload" href="/sjj-blog/assets/js/20.5c098df8.js" as="script"><link rel="prefetch" href="/sjj-blog/assets/js/10.9271e5b8.js"><link rel="prefetch" href="/sjj-blog/assets/js/11.67b9ea44.js"><link rel="prefetch" href="/sjj-blog/assets/js/12.f69e6353.js"><link rel="prefetch" href="/sjj-blog/assets/js/13.ace41b19.js"><link rel="prefetch" href="/sjj-blog/assets/js/14.78670b1e.js"><link rel="prefetch" href="/sjj-blog/assets/js/15.b0aaec82.js"><link rel="prefetch" href="/sjj-blog/assets/js/16.f0d479dc.js"><link rel="prefetch" href="/sjj-blog/assets/js/17.1bacbab3.js"><link rel="prefetch" href="/sjj-blog/assets/js/18.2237a65f.js"><link rel="prefetch" href="/sjj-blog/assets/js/19.7e0f4bf8.js"><link rel="prefetch" href="/sjj-blog/assets/js/21.45bd5038.js"><link rel="prefetch" href="/sjj-blog/assets/js/4.cc582e42.js"><link rel="prefetch" href="/sjj-blog/assets/js/5.9c9443fe.js"><link rel="prefetch" href="/sjj-blog/assets/js/6.370fb6dd.js"><link rel="prefetch" href="/sjj-blog/assets/js/7.e5d26899.js"><link rel="prefetch" href="/sjj-blog/assets/js/8.f6b78670.js"><link rel="prefetch" href="/sjj-blog/assets/js/9.d915a2b8.js">
    <link rel="stylesheet" href="/sjj-blog/assets/css/0.styles.a5cb6817.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar" data-v-1aefc0b4><div data-v-1aefc0b4><div id="loader-wrapper" class="loading-wrapper" data-v-d48f4d20 data-v-1aefc0b4 data-v-1aefc0b4><div class="loader-main" data-v-d48f4d20><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-25ba6db2 data-v-1aefc0b4 data-v-1aefc0b4><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>孙加俊的个人博客</h3> <p class="description" data-v-25ba6db2 data-v-25ba6db2></p> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><span data-v-25ba6db2>孙加俊</span>
            
          <span data-v-25ba6db2>2017 - </span>
          2023
        </a></span></div></div> <div class="hide" data-v-1aefc0b4><header class="navbar" data-v-1aefc0b4><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/sjj-blog/" class="home-link router-link-active"><img src="/sjj-blog/logo.png" alt="孙加俊的个人博客" class="logo"> <span class="site-name">孙加俊的个人博客</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/sjj-blog/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      技术栈
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/sjj-blog/categories/规范/" class="nav-link"><i class="undefined"></i>
  规范
</a></li><li class="dropdown-item"><!----> <a href="/sjj-blog/categories/原生JS/" class="nav-link"><i class="undefined"></i>
  原生JS
</a></li></ul></div></div><div class="nav-item"><a href="/sjj-blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/sjj-blog/docs/theme-reco/" class="nav-link"><i class="undefined"></i>
  vuepress-reco
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系我
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/sir-jun" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-1aefc0b4></div> <aside class="sidebar" data-v-1aefc0b4><div class="personal-info-wrapper" data-v-39576ba9 data-v-1aefc0b4><img src="/sjj-blog/avatar.png" alt="author-avatar" class="personal-img" data-v-39576ba9> <h3 class="name" data-v-39576ba9>
    孙加俊
  </h3> <div class="num" data-v-39576ba9><div data-v-39576ba9><h3 data-v-39576ba9>11</h3> <h6 data-v-39576ba9>Articles</h6></div> <div data-v-39576ba9><h3 data-v-39576ba9>3</h3> <h6 data-v-39576ba9>Tags</h6></div></div> <ul class="social-links" data-v-39576ba9></ul> <hr data-v-39576ba9></div> <nav class="nav-links"><div class="nav-item"><a href="/sjj-blog/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      技术栈
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/sjj-blog/categories/规范/" class="nav-link"><i class="undefined"></i>
  规范
</a></li><li class="dropdown-item"><!----> <a href="/sjj-blog/categories/原生JS/" class="nav-link"><i class="undefined"></i>
  原生JS
</a></li></ul></div></div><div class="nav-item"><a href="/sjj-blog/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/sjj-blog/docs/theme-reco/" class="nav-link"><i class="undefined"></i>
  vuepress-reco
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系我
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://gitee.com/sir-jun" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <!----> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-25ba6db2 data-v-1aefc0b4><h3 class="title" data-v-25ba6db2 data-v-25ba6db2>Vue规范</h3> <!----> <label id="box" class="inputBox" data-v-25ba6db2 data-v-25ba6db2><input type="password" value="" data-v-25ba6db2> <span data-v-25ba6db2>Konck! Knock!</span> <button data-v-25ba6db2>OK</button></label> <div class="footer" data-v-25ba6db2 data-v-25ba6db2><span data-v-25ba6db2><i class="iconfont reco-theme" data-v-25ba6db2></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-25ba6db2>vuePress-theme-reco</a></span> <span data-v-25ba6db2><i class="iconfont reco-copyright" data-v-25ba6db2></i> <a data-v-25ba6db2><span data-v-25ba6db2>孙加俊</span>
            
          <span data-v-25ba6db2>2017 - </span>
          2023
        </a></span></div></div> <div data-v-1aefc0b4><main class="page"><section><div class="page-title"><h1 class="title">Vue规范</h1> <div data-v-f875f3fc><i class="iconfont reco-account" data-v-f875f3fc><span data-v-f875f3fc>孙加俊</span></i> <i class="iconfont reco-date" data-v-f875f3fc><span data-v-f875f3fc>7/20/2023</span></i> <!----> <i class="tags iconfont reco-tag" data-v-f875f3fc><span class="tag-item" data-v-f875f3fc>规范</span></i></div></div> <div class="theme-reco-content content__default"><h1 id="vue-规范"><a href="#vue-规范" class="header-anchor">#</a> Vue 规范</h1> <h2 id="vue-编码基础"><a href="#vue-编码基础" class="header-anchor">#</a> Vue 编码基础</h2> <p>*vue 项目规范以 Vue 官方规范 （https://cn.vuejs.org/v2/style-guide/） 中的 A 规范为基础，在 其上面进行项目开发，故所有代码均遵守该规范。 请仔仔细细阅读 Vue 官方规范，切记，此为第一步。</p> <h2 id="组件规范"><a href="#组件规范" class="header-anchor">#</a> 组件规范</h2> <h3 id="_1-组件名为多个单词"><a href="#_1-组件名为多个单词" class="header-anchor">#</a> 1. 组件名为多个单词</h3> <ul><li>组件名应该始终是多个单词组成（大于等于 2），且命名规范为 kebab-case 格式。</li> <li>这样做可以避免跟现有的以及未来的 HTML 元素相冲突，因为所有的 HTML 元素名称都是单个 单词的。</li></ul> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">//good</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span> <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'TodoItem'</span> <span class="token comment">// ... };</span>
<span class="token comment">//bad</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span> <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'Todo'</span><span class="token punctuation">,</span> <span class="token comment">// ... }</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span> <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'todo-item'</span><span class="token punctuation">,</span> <span class="token comment">// ... }</span>
</code></pre></div><h3 id="_2-组件文件名为-pascal-case-格式"><a href="#_2-组件文件名为-pascal-case-格式" class="header-anchor">#</a> 2. 组件文件名为 pascal-case 格式</h3> <div class="language- extra-class"><pre class="language-text"><code>//good
components/ |- my-component.vue
</code></pre></div><div class="language- extra-class"><pre class="language-text"><code>//bad
components/ |- myComponent.vue |- MyComponent.vue
</code></pre></div><h3 id="_3-基础组件文件名为-base-开头-使用完整单词而不是缩写"><a href="#_3-基础组件文件名为-base-开头-使用完整单词而不是缩写" class="header-anchor">#</a> 3. 基础组件文件名为 base 开头，使用完整单词而不是缩写</h3> <div class="language- extra-class"><pre class="language-text"><code>//good
components/
|- base-button.vue
|- base-table.vue
|- base-icon.vue
</code></pre></div><div class="language- extra-class"><pre class="language-text"><code>//bad
components/
|- MyButton.vue
|- VueTable.vue
|- Icon.vue
</code></pre></div><h3 id="_4-和父组件紧密耦合的子组件应该以父组件名作为前缀命名"><a href="#_4-和父组件紧密耦合的子组件应该以父组件名作为前缀命名" class="header-anchor">#</a> 4. 和父组件紧密耦合的子组件应该以父组件名作为前缀命名</h3> <div class="language- extra-class"><pre class="language-text"><code>//good
components/
|- todo-list.vue
|- todo-list-item.vue
|- todo-list-item-button.vue
|- user-profile-options.vue （完整单词）
</code></pre></div><div class="language- extra-class"><pre class="language-text"><code>//bad
components/
|- TodoList.vue
|- TodoItem.vue
|- TodoButton.vue
|- UProfOpts.vue （使用了缩写）
</code></pre></div><h3 id="_5-在-template-模版中使用组件-应使用大驼峰模式-并且使用-自闭合组件"><a href="#_5-在-template-模版中使用组件-应使用大驼峰模式-并且使用-自闭合组件" class="header-anchor">#</a> 5. 在 Template 模版中使用组件，应使用大驼峰模式，并且使用 自闭合组件</h3> <div class="language-vue extra-class"><pre class="language-vue"><code><span class="token comment">&lt;!-- good --&gt;</span>
<span class="token comment">&lt;!-- 在单文件组件、字符串模板和 JSX 中 --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>MyComponent</span> <span class="token punctuation">/&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>Row</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>table</span> <span class="token attr-name">:column</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>data<span class="token punctuation">&quot;</span></span><span class="token punctuation">/&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>Row</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><div class="language-vue extra-class"><pre class="language-vue"><code><span class="token comment">&lt;!-- bad --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>my-component</span> <span class="token punctuation">/&gt;</span></span> <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>row</span><span class="token punctuation">&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>table</span> <span class="token attr-name">:column</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>data<span class="token punctuation">&quot;</span></span><span class="token punctuation">/&gt;</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>row</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><h3 id="_6-组件的-data-必须是一个函数"><a href="#_6-组件的-data-必须是一个函数" class="header-anchor">#</a> 6. 组件的 data 必须是一个函数</h3> <ul><li>当在组件中使用 data 属性的时候（除了 new Vue 外的任何地方），它的值必须是返回一个对 象的函数。</li> <li>因为如果直接是一个对象的话，子组件之间的属性值会互相影响。</li></ul> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">//good</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  <span class="token function">data</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token punctuation">{</span> <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">&quot;jack&quot;</span> <span class="token punctuation">}</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>
<span class="token comment">//bad</span>
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span> <span class="token literal-property property">data</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">&quot;jack&quot;</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span>
</code></pre></div><h3 id="_7-prop-定义应该尽量详细"><a href="#_7-prop-定义应该尽量详细" class="header-anchor">#</a> 7. Prop 定义应该尽量详细</h3> <ul><li>必须使用小驼峰命名</li> <li>必须指定类型</li> <li>必须加上注释，表明其含义</li> <li>必须加上 required 或者 default，两者二选其一</li> <li>如果有业务需要，必须加上 validator 验证</li></ul> <div class="language-js extra-class"><pre class="language-js"><code><span class="token literal-property property">props</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token comment">// 组件状态，用于控制组件的颜色</span>
     <span class="token literal-property property">status</span><span class="token operator">:</span> <span class="token punctuation">{</span>
          <span class="token literal-property property">type</span><span class="token operator">:</span> String<span class="token punctuation">,</span> <span class="token literal-property property">required</span><span class="token operator">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
           <span class="token function-variable function">validator</span><span class="token operator">:</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">value</span><span class="token punctuation">)</span> <span class="token punctuation">{</span> <span class="token keyword">return</span> <span class="token punctuation">[</span> <span class="token string">'succ'</span><span class="token punctuation">,</span> <span class="token string">'info'</span><span class="token punctuation">,</span> <span class="token string">'error'</span> <span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">indexOf</span><span class="token punctuation">(</span>value<span class="token punctuation">)</span> <span class="token operator">!==</span> <span class="token operator">-</span><span class="token number">1</span> <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
     <span class="token comment">// 用户级别，用于显示皇冠个数 userLevel：</span>
     <span class="token punctuation">{</span>
        <span class="token literal-property property">type</span><span class="token operator">:</span> String<span class="token punctuation">,</span>
        <span class="token literal-property property">required</span><span class="token operator">:</span> <span class="token boolean">true</span>
    <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre></div><h3 id="_8-为组件样式设置作用域"><a href="#_8-为组件样式设置作用域" class="header-anchor">#</a> 8. 为组件样式设置作用域</h3> <div class="language-html extra-class"><pre class="language-html"><code><span class="token comment">&lt;!-- good --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
     <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>btn btn-close<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>X<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
<span class="token comment">&lt;!-- 使用 `scoped` 特性 --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span> <span class="token attr-name">scoped</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css"> <span class="token selector">.btn-close</span> <span class="token punctuation">{</span> <span class="token property">background-color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span> <span class="token punctuation">}</span> </span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><div class="language-html extra-class"><pre class="language-html"><code><span class="token comment">&lt;!-- bad --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>button</span> <span class="token attr-name">class</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>btn btn-close<span class="token punctuation">&quot;</span></span><span class="token punctuation">&gt;</span></span>X<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>button</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
<span class="token comment">&lt;!-- 没有使用 `scoped` 特性 --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css"> <span class="token selector">.btn-close</span> <span class="token punctuation">{</span> <span class="token property">background-color</span><span class="token punctuation">:</span> red<span class="token punctuation">;</span> <span class="token punctuation">}</span> </span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><h3 id="_9-如果特性元素较多-应该主动换行"><a href="#_9-如果特性元素较多-应该主动换行" class="header-anchor">#</a> 9. 如果特性元素较多，应该主动换行</h3> <div class="language-html extra-class"><pre class="language-html"><code><span class="token comment">&lt;!-- good --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>MyComponent</span>
  <span class="token attr-name">foo</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>a<span class="token punctuation">&quot;</span></span>
  <span class="token attr-name">bar</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>b<span class="token punctuation">&quot;</span></span>
  <span class="token attr-name">baz</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>c<span class="token punctuation">&quot;</span></span>
  <span class="token attr-name">foo</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>a<span class="token punctuation">&quot;</span></span>
  <span class="token attr-name">bar</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>b<span class="token punctuation">&quot;</span></span>
  <span class="token attr-name">baz</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>c<span class="token punctuation">&quot;</span></span>
  <span class="token attr-name">foo</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>a<span class="token punctuation">&quot;</span></span>
  <span class="token attr-name">bar</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>b<span class="token punctuation">&quot;</span></span>
  <span class="token attr-name">baz</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>c<span class="token punctuation">&quot;</span></span>
<span class="token punctuation">/&gt;</span></span>
</code></pre></div><div class="language-html extra-class"><pre class="language-html"><code><span class="token comment">&lt;!-- bad --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>MyComponent</span> <span class="token attr-name">foo</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>a<span class="token punctuation">&quot;</span></span>  <span class="token attr-name">bar</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>b<span class="token punctuation">&quot;</span></span>  <span class="token attr-name">baz</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>c<span class="token punctuation">&quot;</span></span>  <span class="token attr-name">foo</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>a<span class="token punctuation">&quot;</span></span>  <span class="token attr-name">bar</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>b<span class="token punctuation">&quot;</span></span>  <span class="token attr-name">baz</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>c<span class="token punctuation">&quot;</span></span>  <span class="token attr-name">foo</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>a<span class="token punctuation">&quot;</span></span>  <span class="token attr-name">bar</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>b<span class="token punctuation">&quot;</span></span>  <span class="token attr-name">baz</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>c<span class="token punctuation">&quot;</span></span>  <span class="token attr-name">foo</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>a<span class="token punctuation">&quot;</span></span>  <span class="token attr-name">bar</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>b<span class="token punctuation">&quot;</span></span>  <span class="token attr-name">baz</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>c<span class="token punctuation">&quot;</span></span> <span class="token punctuation">/&gt;</span></span>
</code></pre></div><h2 id="模板中使用简单的表达式"><a href="#模板中使用简单的表达式" class="header-anchor">#</a> 模板中使用简单的表达式</h2> <ul><li>组件模板应该只包含简单的表达式，复杂的表达式则应该重构为计算属性或方法。</li> <li>复杂表达式会 让你的模板变得不那么声明式。我们应该尽量描述应该出现的是什么，而非如何计算那个值。</li> <li>而 且计算属性和方法使得代码可以重用。</li></ul> <div class="language-vue extra-class"><pre class="language-vue"><code><span class="token comment">&lt;!-- good --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>{{ normalizedFullName }}<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
<span class="token comment">&lt;!-- 复杂表达式已经移入一个计算属性 --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript">
<span class="token keyword">export</span> <span class="token keyword">default</span> <span class="token punctuation">{</span>
  <span class="token literal-property property">computed</span><span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token function-variable function">normalizedFullName</span><span class="token operator">:</span> <span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token keyword">return</span> <span class="token keyword">this</span><span class="token punctuation">.</span>fullName
        <span class="token punctuation">.</span><span class="token function">split</span><span class="token punctuation">(</span><span class="token string">&quot; &quot;</span><span class="token punctuation">)</span>
        <span class="token punctuation">.</span><span class="token function">map</span><span class="token punctuation">(</span><span class="token keyword">function</span> <span class="token punctuation">(</span><span class="token parameter">word</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
          <span class="token keyword">return</span>
          word<span class="token punctuation">[</span><span class="token number">0</span><span class="token punctuation">]</span><span class="token punctuation">.</span><span class="token function">toUpperCase</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">+</span> word<span class="token punctuation">.</span><span class="token function">slice</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span>
        <span class="token punctuation">}</span><span class="token punctuation">)</span>
        <span class="token punctuation">.</span><span class="token function">join</span><span class="token punctuation">(</span><span class="token string">&quot; &quot;</span><span class="token punctuation">)</span>
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
<span class="token punctuation">}</span>
</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><div class="language-vue extra-class"><pre class="language-vue"><code><span class="token comment">&lt;!-- bad --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>p</span><span class="token punctuation">&gt;</span></span>
    {{
      fullName
        .split(&quot; &quot;)
        .map(function (word) {
          return word[0].toUpperCase() + word.slice(1)
        })
        .join(&quot; &quot;)
    }}
  <span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>p</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><h2 id="指令都使用缩写形式"><a href="#指令都使用缩写形式" class="header-anchor">#</a> 指令都使用缩写形式</h2> <ul><li>指令推荐都使用缩写形式，(用 : 表示 v-bind: 、用 @ 表示 v-on: 和用 # 表示 v-slot:)</li></ul> <div class="language-vue extra-class"><pre class="language-vue"><code><span class="token comment">&lt;!-- good --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name">@input</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>onInput<span class="token punctuation">&quot;</span></span> <span class="token attr-name">@focus</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>onFocus<span class="token punctuation">&quot;</span></span> <span class="token punctuation">&gt;</span></span>
</code></pre></div><div class="language-vue extra-class"><pre class="language-vue"><code><span class="token comment">&lt;!-- bad --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>input</span> <span class="token attr-name"><span class="token namespace">v-on:</span>input</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>onInput<span class="token punctuation">&quot;</span></span> <span class="token attr-name">@focus</span><span class="token attr-value"><span class="token punctuation attr-equals">=</span><span class="token punctuation">&quot;</span>onFocus<span class="token punctuation">&quot;</span></span> <span class="token punctuation">&gt;</span></span>
</code></pre></div><h2 id="标签顺序保持一致"><a href="#标签顺序保持一致" class="header-anchor">#</a> 标签顺序保持一致</h2> <ul><li>单文件组件应该总是让标签顺序保持为</li></ul> <div class="language-vue extra-class"><pre class="language-vue"><code><span class="token comment">&lt;!-- good --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>...<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript"><span class="token operator">...</span></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">...</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><div class="language-vue extra-class"><pre class="language-vue"><code><span class="token comment">&lt;!-- bad --&gt;</span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>template</span><span class="token punctuation">&gt;</span></span>...<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>template</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>style</span><span class="token punctuation">&gt;</span></span><span class="token style"><span class="token language-css">...</span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>style</span><span class="token punctuation">&gt;</span></span>
<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>script</span><span class="token punctuation">&gt;</span></span><span class="token script"><span class="token language-javascript"><span class="token operator">...</span></span></span><span class="token tag"><span class="token tag"><span class="token punctuation">&lt;/</span>script</span><span class="token punctuation">&gt;</span></span>
</code></pre></div><h2 id="必须为-v-for-设置键值-key"><a href="#必须为-v-for-设置键值-key" class="header-anchor">#</a> 必须为 v-for 设置键值 key</h2> <h2 id="v-show-与-v-if-选择"><a href="#v-show-与-v-if-选择" class="header-anchor">#</a> v-show 与 v-if 选择</h2> <ul><li>如果运行时，需要非常频繁地切换，使用 v-show ；</li> <li>如果在运行时，条件很少改变，使用 v-if。</li></ul> <h2 id="script-标签内部结构顺序"><a href="#script-标签内部结构顺序" class="header-anchor">#</a> script 标签内部结构顺序</h2> <p>name &gt; components &gt; mixins &gt; props &gt; data &gt; computed &gt; watch &gt; filter &gt; 钩子函数（钩子函数按其 执行顺序） &gt; methods</p> <h2 id="vue-router-规范"><a href="#vue-router-规范" class="header-anchor">#</a> Vue Router 规范</h2> <h3 id="_1-页面跳转数据传递使用路由参数"><a href="#_1-页面跳转数据传递使用路由参数" class="header-anchor">#</a> 1.页面跳转数据传递使用路由参数</h3> <p>页面跳转，</p> <ul><li>例如 A 页面跳转到 B 页面，需要将 A 页面的数据传递到 B 页面，
<ul><li>推荐使用 路由 参数进行传参，而不是将需要传递的数据保存 vuex，</li> <li>然后在 B 页面取出 vuex 的数据，因为如果在 B 页面刷新会导致 vuex 数据丢失，导致 B 页面无法正常显示数据。</li></ul></li></ul> <div class="language-js extra-class"><pre class="language-js"><code><span class="token keyword">let</span> id <span class="token operator">=</span> <span class="token string">&quot; 123&quot;</span>
<span class="token keyword">this</span><span class="token punctuation">.</span>$router<span class="token punctuation">.</span><span class="token function">push</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">&quot;userCenter&quot;</span><span class="token punctuation">,</span> <span class="token literal-property property">query</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token literal-property property">id</span><span class="token operator">:</span> id <span class="token punctuation">}</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre></div><h3 id="_2-使用路由懒加载-延迟加载-机制"><a href="#_2-使用路由懒加载-延迟加载-机制" class="header-anchor">#</a> 2.使用路由懒加载（延迟加载）机制</h3> <div class="language-js extra-class"><pre class="language-js"><code><span class="token punctuation">{</span>
    <span class="token literal-property property">path</span><span class="token operator">:</span> <span class="token string">'/uploadAttachment'</span><span class="token punctuation">,</span>
    <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'uploadAttachment'</span><span class="token punctuation">,</span>
    <span class="token literal-property property">meta</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token literal-property property">title</span><span class="token operator">:</span> <span class="token string">'上传附件'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token function-variable function">component</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=&gt;</span> <span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">'@/view/components/uploadAttachment/index.vue'</span><span class="token punctuation">)</span> 
<span class="token punctuation">}</span>
</code></pre></div><h3 id="_3-router-中的命名规范"><a href="#_3-router-中的命名规范" class="header-anchor">#</a> 3.router 中的命名规范</h3> <ul><li>path、childrenPoints 命名规范采用 kebab-case 命名规范（尽量 vue 文件的目录结构保持一致， 因为目录、文件名都是 kebab-case，这样很方便找到对应的文件）</li> <li>name 命名规范采用 kebab-case 命名规范且和 component 组件名保持一致！（因为要保持 keep-alive 特性，keep-alive 按照 component 的 name 进行缓存，所以两者必须高度保持一致）</li></ul> <div class="language-js extra-class"><pre class="language-js"><code><span class="token comment">// 动态加载</span>
<span class="token keyword">export</span> <span class="token keyword">const</span> reload <span class="token operator">=</span>
 <span class="token punctuation">[</span>
     <span class="token punctuation">{</span>
          <span class="token literal-property property">path</span><span class="token operator">:</span> <span class="token string">'/reload'</span><span class="token punctuation">,</span>
           <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'reload'</span><span class="token punctuation">,</span>
           <span class="token literal-property property">component</span><span class="token operator">:</span> Main<span class="token punctuation">,</span>
           <span class="token literal-property property">meta</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token literal-property property">title</span><span class="token operator">:</span> <span class="token string">'动态加载'</span><span class="token punctuation">,</span>
           <span class="token literal-property property">icon</span><span class="token operator">:</span> <span class="token string">'icon iconfont'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
          <span class="token literal-property property">children</span><span class="token operator">:</span> <span class="token punctuation">[</span>
                <span class="token punctuation">{</span>
                <span class="token literal-property property">path</span><span class="token operator">:</span> <span class="token string">'/reload/smart-reload-list'</span><span class="token punctuation">,</span>
                <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'SmartReloadList'</span><span class="token punctuation">,</span>
                <span class="token literal-property property">meta</span><span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token literal-property property">title</span><span class="token operator">:</span> <span class="token string">'SmartReload'</span><span class="token punctuation">,</span>
                <span class="token literal-property property">childrenPoints</span><span class="token operator">:</span>
                <span class="token punctuation">[</span>
                        <span class="token punctuation">{</span>
                            <span class="token literal-property property">title</span><span class="token operator">:</span> <span class="token string">'查询'</span><span class="token punctuation">,</span>
                            <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'smart-reload-search'</span>
                        <span class="token punctuation">}</span><span class="token punctuation">,</span>
                       <span class="token punctuation">{</span>
                            <span class="token literal-property property">title</span><span class="token operator">:</span> <span class="token string">'执行 reload'</span><span class="token punctuation">,</span>
                            <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'smart-reload-update'</span>
                        <span class="token punctuation">}</span><span class="token punctuation">,</span>
                        <span class="token punctuation">{</span>
                            <span class="token literal-property property">title</span><span class="token operator">:</span> <span class="token string">'查看执行结果'</span><span class="token punctuation">,</span>
                            <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'smart-reload-result'</span>
                       <span class="token punctuation">}</span>
                <span class="token punctuation">]</span>
 <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token literal-property property">component</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token operator">&gt;</span><span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">'@/views/reload/smart-reload/smart-reload-list.vue'</span><span class="token punctuation">)</span> <span class="token punctuation">}</span><span class="token punctuation">]</span>
</code></pre></div><h3 id="_4-router-中的-path-命名规范"><a href="#_4-router-中的-path-命名规范" class="header-anchor">#</a> 4.router 中的 path 命名规范</h3> <ul><li>path 除了采用 kebab-case 命名规范以外，必须以 / 开头，即使是 children 里的 path 也要以 / 开 头。</li> <li>目的： 经常有这样的场景：某个页面有问题，要立刻找到这个 vue 文件，如果不用以/开头，path 为 parent 和 children 组成的，可能经常需要在 router 文件里搜索多次才能找到，而如果以/开头，则能立 刻搜索到对应的组件。</li></ul> <div class="language-js extra-class"><pre class="language-js"><code>   <span class="token punctuation">{</span> 
       <span class="token literal-property property">path</span><span class="token operator">:</span> <span class="token string">'/file'</span><span class="token punctuation">,</span> 
       <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'File'</span><span class="token punctuation">,</span> 
       <span class="token literal-property property">component</span><span class="token operator">:</span> Main<span class="token punctuation">,</span> 
       <span class="token literal-property property">meta</span><span class="token operator">:</span> <span class="token punctuation">{</span> 
           <span class="token literal-property property">title</span><span class="token operator">:</span> <span class="token string">'文件服务'</span><span class="token punctuation">,</span> 
           <span class="token literal-property property">icon</span><span class="token operator">:</span> <span class="token string">'ios-cloud-upload'</span> 
           <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token literal-property property">children</span><span class="token operator">:</span> <span class="token punctuation">[</span>
            <span class="token punctuation">{</span> 
                <span class="token literal-property property">path</span><span class="token operator">:</span> <span class="token string">'/file/file-list'</span><span class="token punctuation">,</span> 
                <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'FileList'</span><span class="token punctuation">,</span> 
                <span class="token literal-property property">component</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token operator">&gt;</span><span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">'@/views/file/file-list.vue'</span><span class="token punctuation">)</span> 
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
           <span class="token punctuation">{</span> 
                    <span class="token literal-property property">path</span><span class="token operator">:</span> <span class="token string">'/file/file-add'</span><span class="token punctuation">,</span> 
                    <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'FileAdd'</span><span class="token punctuation">,</span> 
                    <span class="token literal-property property">component</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token operator">&gt;</span><span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">'@/views/file/file-add.vue'</span><span class="token punctuation">)</span> 
                <span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token punctuation">{</span> 
                     <span class="token literal-property property">path</span><span class="token operator">:</span> <span class="token string">'/file/file-update'</span><span class="token punctuation">,</span>
                    <span class="token literal-property property">name</span><span class="token operator">:</span> <span class="token string">'FileUpdate'</span><span class="token punctuation">,</span>
                    <span class="token literal-property property">component</span><span class="token operator">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span> <span class="token operator">&gt;</span><span class="token keyword">import</span><span class="token punctuation">(</span><span class="token string">'@/views/file/file-update.vue'</span><span class="token punctuation">)</span> 
             <span class="token punctuation">}</span>
           <span class="token punctuation">]</span> 
        <span class="token punctuation">}</span>
</code></pre></div><h1 id="目录规范"><a href="#目录规范" class="header-anchor">#</a> 目录规范</h1> <h2 id="目录说明"><a href="#目录说明" class="header-anchor">#</a> 目录说明</h2> <ul><li>目录名按照上面的命名规范，其中 components 组件用大写驼峰，</li> <li>其余除 components 组件目 录外的所有目录均使用 kebab-case 命名。</li></ul> <div class="language- extra-class"><pre class="language-text"><code>src 源码目录 
|-- api 所有 api 接口 
|-- assets 静态资源，images, icons, styles 等 
|-- components 公用组件 
|-- config 配置信息 
|-- constants 常量信息，项目所有 Enum, 全局常量等 
|-- directives 自定义指令 
|-- filters 过滤器，全局工具 
|-- datas 模拟数据，临时存放 
|-- lib 外部引用的插件存放及修改文件 
|-- mock 模拟接口，临时存放 
|-- plugins 插件，全局使用 
|-- router 路由，统一管理 
|-- store vuex, 统一管理 
|-- themes 自定义样式主题 
|-- views 视图目录 
        |-- role role        模块名 
        |-- role-list.vue   role 列表页面
        |-- role-add.vue    role 新建页面 
        |-- role-update.vue role 更新页面 
        |-- index.less      role 模块样式 
        |-- components      role 模块通用组件文件夹 
    |-- employee        employee 模块
        |-- employee employee        模块名 
        |-- employee-list.vue   employee 列表页面
        |-- employee-add.vue    employee 新建页面 
        |-- employee-update.vue employee 更新页面 
        |-- index.less      employee 模块样式 
        |-- components      employee 模块通用组件文件夹 
</code></pre></div><h2 id="assets-目录"><a href="#assets-目录" class="header-anchor">#</a> assets 目录</h2> <ul><li>assets 为静态资源，里面存放 images, styles, icons 等静态资源，静态资源命名格式为 kebab-case</li></ul> <div class="language- extra-class"><pre class="language-text"><code>|assets
|-- icons
|-- images
| |-- background-color.png
| |-- upload-header.png
|-- styles
</code></pre></div><h2 id="components-目录"><a href="#components-目录" class="header-anchor">#</a> components 目录</h2> <ul><li>此目录应按照组件进行目录划分，目录命名为 kebab-case，组件命名规则也为 kebab-case</li></ul> <div class="language- extra-class"><pre class="language-text"><code>|components
|-- error-log
| |-- index.vue
| |-- index.less
|-- markdown-editor
| |-- index.vue | |-- index.js |--
</code></pre></div><h2 id="router-与-store-目录"><a href="#router-与-store-目录" class="header-anchor">#</a> router 与 store 目录</h2> <ul><li>这两个目录一定要将业务进行拆分，不能放到一个 js 文件里。</li> <li>router 尽量按照 views 中的结构保持一致</li> <li>store 按照业务进行拆分不同的 js 文件</li></ul> <h2 id="views-目录"><a href="#views-目录" class="header-anchor">#</a> views 目录</h2> <ul><li>命名要与后端、router、api 等保持一致components 中组件要使用 kebab-case规则</li></ul> <div class="language- extra-class"><pre class="language-text"><code>-- views 视图目录
| |-- role role 模块名
| | |-- role-list.vue role 列表页面
| | |-- role-add.vue role 新建页面
| | |-- role-update.vue role 更新页面
| | |-- index.less role 模块样式
| | |-- components role 模块通用组件文件夹
| | | |-- role-header.vue role 头部组件
| | | |-- role-modal.vue role 弹出框组件
| |-- employee employee 模块
| |-- behavior-log 行为日志 log 模块
| |-- code-generator 代码生成器模块
</code></pre></div><h2 id="注释说明"><a href="#注释说明" class="header-anchor">#</a> 注释说明</h2> <p>整理必须加注释的地方</p> <ul><li>公共组件使用说明</li> <li>api 目录的接口 js 文件必须加注释</li> <li>store 中的 state, mutation, action 等必须加注释</li> <li>vue 文件中的 template 必须加注释，若文件较大添加 start end 注释</li> <li>vue 文件的 methods，每个 method 必须添加注释</li> <li>vue 文件的 data, 非常见单词要加注释</li></ul> <h2 id="其他"><a href="#其他" class="header-anchor">#</a> 其他</h2> <h3 id="_1-尽量不要手动操作-dom"><a href="#_1-尽量不要手动操作-dom" class="header-anchor">#</a> 1.尽量不要手动操作 DOM</h3> <ul><li>因使用 vue 框架，所以在项目开发中尽量使用 vue 的数据驱动更新 DOM，尽量（不到万不得 已）不要手动操作 DOM，包括：增删改 dom 元素、以及更改样式、添加事件等。</li></ul> <h3 id="_3-删除无用代码"><a href="#_3-删除无用代码" class="header-anchor">#</a> 3.删除无用代码</h3> <ul><li>因使用了 git/svn 等代码版本工具，对于无用代码必须及时删除，例如：一些调试的 console 语句、无用的弃用功能代码。</li></ul></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">10/9/2023, 2:58:10 PM</span></div></footer> <!----> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-cb1513f6><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#vue-编码基础" class="sidebar-link reco-side-vue-编码基础" data-v-cb1513f6>Vue 编码基础</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#组件规范" class="sidebar-link reco-side-组件规范" data-v-cb1513f6>组件规范</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_1-组件名为多个单词" class="sidebar-link reco-side-_1-组件名为多个单词" data-v-cb1513f6>1\. 组件名为多个单词</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_2-组件文件名为-pascal-case-格式" class="sidebar-link reco-side-_2-组件文件名为-pascal-case-格式" data-v-cb1513f6>2\. 组件文件名为 pascal-case 格式</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_3-基础组件文件名为-base-开头-使用完整单词而不是缩写" class="sidebar-link reco-side-_3-基础组件文件名为-base-开头-使用完整单词而不是缩写" data-v-cb1513f6>3\. 基础组件文件名为 base 开头，使用完整单词而不是缩写</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_4-和父组件紧密耦合的子组件应该以父组件名作为前缀命名" class="sidebar-link reco-side-_4-和父组件紧密耦合的子组件应该以父组件名作为前缀命名" data-v-cb1513f6>4\. 和父组件紧密耦合的子组件应该以父组件名作为前缀命名</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_5-在-template-模版中使用组件-应使用大驼峰模式-并且使用-自闭合组件" class="sidebar-link reco-side-_5-在-template-模版中使用组件-应使用大驼峰模式-并且使用-自闭合组件" data-v-cb1513f6>5\. 在 Template 模版中使用组件，应使用大驼峰模式，并且使用 自闭合组件</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_6-组件的-data-必须是一个函数" class="sidebar-link reco-side-_6-组件的-data-必须是一个函数" data-v-cb1513f6>6\. 组件的 data 必须是一个函数</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_7-prop-定义应该尽量详细" class="sidebar-link reco-side-_7-prop-定义应该尽量详细" data-v-cb1513f6>7\. Prop 定义应该尽量详细</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_8-为组件样式设置作用域" class="sidebar-link reco-side-_8-为组件样式设置作用域" data-v-cb1513f6>8\. 为组件样式设置作用域</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_9-如果特性元素较多-应该主动换行" class="sidebar-link reco-side-_9-如果特性元素较多-应该主动换行" data-v-cb1513f6>9\. 如果特性元素较多，应该主动换行</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#模板中使用简单的表达式" class="sidebar-link reco-side-模板中使用简单的表达式" data-v-cb1513f6>模板中使用简单的表达式</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#指令都使用缩写形式" class="sidebar-link reco-side-指令都使用缩写形式" data-v-cb1513f6>指令都使用缩写形式</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#标签顺序保持一致" class="sidebar-link reco-side-标签顺序保持一致" data-v-cb1513f6>标签顺序保持一致</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#必须为-v-for-设置键值-key" class="sidebar-link reco-side-必须为-v-for-设置键值-key" data-v-cb1513f6>必须为 v-for 设置键值 key</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#v-show-与-v-if-选择" class="sidebar-link reco-side-v-show-与-v-if-选择" data-v-cb1513f6>v-show 与 v-if 选择</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#script-标签内部结构顺序" class="sidebar-link reco-side-script-标签内部结构顺序" data-v-cb1513f6>script 标签内部结构顺序</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#vue-router-规范" class="sidebar-link reco-side-vue-router-规范" data-v-cb1513f6>Vue Router 规范</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_1-页面跳转数据传递使用路由参数" class="sidebar-link reco-side-_1-页面跳转数据传递使用路由参数" data-v-cb1513f6>1.页面跳转数据传递使用路由参数</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_2-使用路由懒加载-延迟加载-机制" class="sidebar-link reco-side-_2-使用路由懒加载-延迟加载-机制" data-v-cb1513f6>2.使用路由懒加载（延迟加载）机制</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_3-router-中的命名规范" class="sidebar-link reco-side-_3-router-中的命名规范" data-v-cb1513f6>3.router 中的命名规范</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_4-router-中的-path-命名规范" class="sidebar-link reco-side-_4-router-中的-path-命名规范" data-v-cb1513f6>4.router 中的 path 命名规范</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#目录说明" class="sidebar-link reco-side-目录说明" data-v-cb1513f6>目录说明</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#assets-目录" class="sidebar-link reco-side-assets-目录" data-v-cb1513f6>assets 目录</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#components-目录" class="sidebar-link reco-side-components-目录" data-v-cb1513f6>components 目录</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#router-与-store-目录" class="sidebar-link reco-side-router-与-store-目录" data-v-cb1513f6>router 与 store 目录</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#views-目录" class="sidebar-link reco-side-views-目录" data-v-cb1513f6>views 目录</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#注释说明" class="sidebar-link reco-side-注释说明" data-v-cb1513f6>注释说明</a></li><li class="level-2" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#其他" class="sidebar-link reco-side-其他" data-v-cb1513f6>其他</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_1-尽量不要手动操作-dom" class="sidebar-link reco-side-_1-尽量不要手动操作-dom" data-v-cb1513f6>1.尽量不要手动操作 DOM</a></li><li class="level-3" data-v-cb1513f6><a href="/sjj-blog/blogs/standards/vue-standards.html#_3-删除无用代码" class="sidebar-link reco-side-_3-删除无用代码" data-v-cb1513f6>3.删除无用代码</a></li></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div></div></div>
    <script src="/sjj-blog/assets/js/app.ab5bad9b.js" defer></script><script src="/sjj-blog/assets/js/3.136f62ef.js" defer></script><script src="/sjj-blog/assets/js/1.a27fba8e.js" defer></script><script src="/sjj-blog/assets/js/20.5c098df8.js" defer></script>
  </body>
</html>
